package com.winchain.chainbill.bill.biz.receive.cmd;

import com.shell.bee.acct.transaction.po.AcctTxRec;
import com.shell.bee.base.utils.StringUtil;
import com.shell.framework.command.CallbackContext;
import com.shell.framework.command.CommandContext;
import com.shell.framework.command.ICallback;
import com.shell.framework.command.ICommand;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.biz.Bill;
import com.winchain.chainbill.bill.biz.send.service.BillHoldService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BillHldrCmd<T> implements ICommand<Bill<T>>, ICallback<Bill<T>, AcctTxRec> {
	private final Log logger = LogFactory.getLog(getClass());
	@Autowired
	private BillHoldService billHoldService;

	public boolean execute(CommandContext<Bill<T>> context) throws Exception {
		CbRec bill = ((Bill) context.getSource()).getRec();

		String ownerId = (String) context.getValue("OwnerId");
		if (StringUtil.emptyAndNull(ownerId)) {
			this.logger.warn("warnning:ownerId ����!");
			return true;
		}
		this.billHoldService.own(bill, ownerId);
		return false;
	}

	public boolean callback(CallbackContext<Bill<T>, AcctTxRec> context) throws Exception {
		execute(context);
		return false;
	}
}
